home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Development / 3DMF parser / 1.0 version / MF3DPC / MFRSLNTN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-07  |  4.8 KB  |  178 lines  |  [TEXT/dosa]

  1. /*==============================================================================
  2.  *
  3.  *    File:        MFRSLNTN.C
  4.  *
  5.  *    Function:    Routines for saving information around reference resolution.
  6.  *
  7.  *    Version:    Metafile:    Version 1.0 3DMF files
  8.  *                Package:    Release #2 of this code
  9.  *
  10.  *    Author(s):    Rick Wong (RWW), Duet Development Corp.
  11.  *                John Kelly (JRK), Duet Development Corp.
  12.  *
  13.  *    Copyright:    (c) 1995 by Apple Computer, Inc., all rights reserved.
  14.  *
  15.  *    Change History (most recent first):
  16.  *        FB8_JRK    Segmentation
  17.  *        Fabio    Changed file name to 8 characters
  18.  *        F3H_RWW    Make the resolution stuff work with external files.
  19.  *        F2N_RWW    File created.
  20.  *==============================================================================
  21.  */
  22.  
  23. #include "MFRSLNTN.H"
  24.  
  25. #include <string.h>
  26.  
  27. #include "MF3D.H"
  28. #include "MFERRORS.H"
  29. #include "MFINT64.H"
  30. #include "MFTYPES.H"
  31. #include "MFASSERT.H"
  32. #include "MFINTOBJ.H"
  33. #include "MFMACROS.H"
  34. #include "MFMEMORY.H"
  35.  
  36. #if defined(applec) || defined(__MWERKS__) || defined(THINK_C)
  37. #pragma segment __MF3D__
  38. #endif
  39.  
  40. /*==============================================================================
  41.  *    MF3D_PushResolution
  42.  *
  43.  *    Resolve a reference
  44.  *==============================================================================
  45.  */
  46. MF3DErr
  47. MF3D_PushResolution(
  48.     MF3D_FilePtr        ioMF3DFilePtr,         /* In:  MF3D file structure        */
  49.     MF3DReferenceObjPtr    inMF3DRefObjPtr,     /* In:  reference object        */
  50.     MF3DStorageObjPtr    inExternalFilePtr)    /* In:    external storage object    */
  51. {
  52.     MF3D_FilePtr            newFilePtr;
  53.     MF3DUns32                resState;
  54.     MF3DBinaryFilePosition    returnLoc;
  55.     MF3DErr                    result;
  56.  
  57.     result = kMF3DNoErr;
  58.  
  59.     MFASSERT(ioMF3DFilePtr->resStuff.reference == NULL);
  60.  
  61.     if (inMF3DRefObjPtr->refID == 0)
  62.     {    if (inExternalFilePtr == NULL)
  63.             result = kMF3DErrIllegalRefID;
  64.         else
  65.             resState = MF3D_ResolvingFile;
  66.     }
  67.     else
  68.     {    resState = MF3D_ResolvingReference;
  69.     }
  70.  
  71.     if (result == kMF3DNoErr)
  72.     {    SetInt64ToZero(returnLoc);
  73.         if (inExternalFilePtr != NULL)
  74.         {    /* Got outside object */
  75.             result = MF3DOpenInputStdCFile(
  76.                     inExternalFilePtr->pathName, &newFilePtr);
  77.         }
  78.         else
  79.         {    /* Duplicate current file for reference */
  80.             MF3D_Allocate(newFilePtr);
  81.  
  82.             if (result == kMF3DNoErr)
  83.                 result = MF3DTellPosition(ioMF3DFilePtr, &returnLoc);
  84.  
  85.             if (result == kMF3DNoErr)
  86.                 memcpy(newFilePtr, ioMF3DFilePtr, sizeof(*newFilePtr));
  87.  
  88.             
  89.         }
  90.     }
  91.  
  92.     if (result == kMF3DNoErr && resState == MF3D_ResolvingReference)
  93.     {    MF3DUns32                    objIndex, numObjTableEntries;
  94.         MF3D_ObjectTableEntryPtr    objTableEntryPtr;
  95.  
  96.         numObjTableEntries = newFilePtr->objTable.numObjects;
  97.         objTableEntryPtr = newFilePtr->objTable.objects;
  98.         for (objIndex = 0;
  99.                 objTableEntryPtr->objRefID != inMF3DRefObjPtr->refID;
  100.                 ++objIndex, ++objTableEntryPtr)
  101.         {    if (objIndex >= numObjTableEntries)
  102.             {    result = kMF3DErrReferenceNotFound;
  103.                 break;
  104.             }
  105.         }
  106.  
  107.         if (result == kMF3DNoErr)
  108.         {    result = MF3DSeekPosition(newFilePtr,
  109.                     objTableEntryPtr->objLocation);
  110.         }
  111.  
  112.         if (result != kMF3DNoErr)
  113.         {    if (inExternalFilePtr != NULL)
  114.                 MF3DClose(newFilePtr);
  115.             else
  116.                 MF3D_Free(newFilePtr);
  117.         }
  118.     }
  119.  
  120.     if (result == kMF3DNoErr)
  121.     {    MFASSERT(ioMF3DFilePtr->resStuff.reference == NULL);
  122.  
  123.         newFilePtr->resStuff.parent = ioMF3DFilePtr;
  124.         newFilePtr->resStuff.resState = resState;
  125.         newFilePtr->resStuff.reference = NULL;
  126.         newFilePtr->readBuffer.buf = NULL;
  127.         newFilePtr->inContainer = 0;
  128.         newFilePtr->typeTable.nTypes = 0;
  129.         newFilePtr->typeTable.types = MF3D_Malloc(0);
  130.         /* NOTE: returnLoc is only valid for internal references */
  131.         AssignInt64(newFilePtr->resStuff.returnLoc, returnLoc);
  132.         ioMF3DFilePtr->resStuff.reference = newFilePtr;
  133.     }
  134.  
  135.     return result;
  136. }
  137.  
  138. /*==============================================================================
  139.  *    MF3D_PopResolution
  140.  *
  141.  *    Close inMF3DFilePtr.
  142.  *==============================================================================
  143.  */
  144. MF3DErr
  145. MF3D_PopResolution(
  146.     MF3D_FilePtr    inMF3DFilePtr)
  147. {
  148.     MF3D_FilePtr            parentFilePtr;
  149.     MF3DBinaryFilePosition    zero;
  150.     MF3DErr                    result;
  151.  
  152.     result = kMF3DNoErr;
  153.  
  154.     parentFilePtr = inMF3DFilePtr->resStuff.parent;
  155.     MFASSERT(parentFilePtr != NULL);
  156.  
  157.     if (inMF3DFilePtr->resStuff.reference != NULL)
  158.         result = MF3D_PopResolution(inMF3DFilePtr->resStuff.reference);
  159.  
  160.     parentFilePtr->resStuff.reference = NULL;
  161.  
  162.     /* Was it an external reference? */
  163.     SetInt64ToZero(zero);
  164.     if (CompareInt64(inMF3DFilePtr->resStuff.returnLoc, zero) == 0)
  165.     {    result = MF3DClose(inMF3DFilePtr);
  166.     }
  167.     else
  168.     {    /* NOTE: returnLoc is only valid for internal references */
  169.         result = MF3DSeekPosition(inMF3DFilePtr,
  170.                 inMF3DFilePtr->resStuff.returnLoc);
  171.     }
  172.  
  173.     if (inMF3DFilePtr->resStuff.resState > MF3D_ResolvingFile)
  174.         result = kMF3DErrNotEnoughEndGroups;
  175.  
  176.     return result;
  177. }
  178.